package com.ruibei.ui.fragment;


import butterknife.ButterKnife;
import butterknife.InjectView;

import com.ruibei.R;
import com.ruibei.ui.ApprovalActivity;
import com.ruibei.ui.CalculatorActivity;
import com.ruibei.ui.ContactsActivity;
import com.ruibei.ui.CreateApprovalActivity;
import com.ruibei.ui.HistoryFilterActivity;
import com.ruibei.ui.adapter.WorkGridAdapter;
import com.ruibei.utils.ToastUtils;
import com.ruibei.view.NoScrollGridView;
import com.ruibei.view.TitleBarView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

/**
 * 工作页面
 *
 * @author limingyan
 *
 */
public class WorkFragment extends BaseFragment{
	private static final String TAG = "HistoryFragment";
	private Context mContext;
	private View mBaseView;
	
	//标题栏
	@InjectView(R.id.history_title_bar)
	TitleBarView mTitleBarView;
	@InjectView(R.id.work_gridview)
	NoScrollGridView mWorkGrid;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		mContext = getActivity();
		mBaseView = inflater.inflate(R.layout.fragment_work, container,
				false);
		ButterKnife.inject(this, mBaseView);
		initView();
		
		return mBaseView;
	}
	
	private void initView() {
		mTitleBarView.setCommonTitle(View.GONE, View.VISIBLE, View.VISIBLE);
		mTitleBarView.setTitleText(R.string.work_title);
		mWorkGrid.setAdapter(new WorkGridAdapter(getActivity()));
		mWorkGrid.setOnItemClickListener(mOnItemClickListener);
	}

	private OnItemClickListener mOnItemClickListener = new OnItemClickListener(){
		
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int positon,
				long arg3) {
			switch (positon) {
			case 0:
				//审评
				startActivity(new Intent(WorkFragment.this.getActivity(), 
						ApprovalActivity.class));
				break;
			case 1:
				//新建审评
				startActivity(new Intent(WorkFragment.this.getActivity(), 
						CreateApprovalActivity.class));
				break;
			case 2:
				//检索审评
				startActivity(new Intent(WorkFragment.this.getActivity(), 
						HistoryFilterActivity.class));
				getActivity().overridePendingTransition(R.anim.activity_up,
					R.anim.fade_out);//定义动画样式
				break;
			case 3:
				//模拟计算器
				startActivity(new Intent(WorkFragment.this.getActivity(), 
						CalculatorActivity.class));
				break;
			case 4:
				//test
				startActivity(new Intent(WorkFragment.this.getActivity(), 
						ContactsActivity.class));
				ToastUtils.showShort("功能尚未开发");
				break;
			case 5:
				//
				ToastUtils.showShort("功能尚未开发");
				break;
			case 6:
				//
				ToastUtils.showShort("功能尚未开发");
				break;
			case 7:
				//
				ToastUtils.showShort("功能尚未开发");
				break;
			case 8:
				//
				ToastUtils.showShort("功能尚未开发");
				break;	

			default:
				break;
			}
		}
		
	};
	
}
